﻿namespace HRM.CORE
{
    using DevExpress.Utils;
    using DevExpress.XtraBars;
    using DevExpress.XtraEditors;
    using DevExpress.XtraTreeList;
    using DevExpress.XtraTreeList.Columns;
    using Common.Class; using APP.HELPER.Utils.Language; using Security.Security; using Dictionary.ERP;
    using HRM.CORE;
    
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms; using Common;

    public class xucRecruitment1 : UserControl
    {
        private BarButtonItem barButtonItem1;
        private BarButtonItem barButtonItem2;
        private BarButtonItem barButtonItem3;
        private BarButtonItem barButtonItem4;
        private BarButtonItem barButtonItem5;
        private BarButtonItem barButtonItem6;
        private BarButtonItem barButtonItem7;
        private BarDockControl barDockControlBottom;
        private BarDockControl barDockControlLeft;
        private BarDockControl barDockControlRight;
        private BarDockControl barDockControlTop;
        private BarManager barManager1;
        private BarMdiChildrenListItem barMdiChildrenListItem1;
        private BarSubItem barSubItem1;
        private BarToolbarsListItem barToolbarsListItem1;
        private BarButtonItem bbiAddRecruitment;
        private BarButtonItem bbiDeleteRecruitment;
        private BarButtonItem bbiEditRecruitment;
        private BarButtonItem bbiProperties;
        private TreeListColumn colRecruitmentName;
        private IContainer components = null;
        private DataTable dt1;
        public DevExpress.Utils.ImageCollection imageCollection2;
        private DevExpress.Utils.ImageCollection imgTree;
        private Point m_Point;
        private PopupMenu popupRecruitment;
        private ToolTipController toolTip1;
        private TreeList treeList1;

        public event SelectedEventHander Selected;

        public xucRecruitment1()
        {
            this.InitializeComponent();
            this.InitMultiLanguages();
        }

        public void AddRecruitment()
        {
            xfmRecruitmentAdd add = new xfmRecruitmentAdd(Actions.Add);
            add.Added += new xfmRecruitmentAdd.AddedEventHander(this.frm_Added);
            add.ShowDialog();
        }

        private void bbiDeleteRecruitment_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.RecruitmentDelete(this.treeList1.CalcHitInfo(this.m_Point));
        }

        private void bbiEditRecruitment_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.RecruitmentChange(this.treeList1.CalcHitInfo(this.m_Point));
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void frm_Added(object sender, HRM_RECRUITMENT Item)
        {
            if (Item.Status == 0)
            {
                this.treeList1.AppendNode(new object[] { Item.RecruitmentCode.ToString(), Item.RecruitmentName.ToString(), "All", Item.FromDate.ToShortDateString(), Item.ToDate.ToShortDateString(), "Đang l\x00ean kế hoạch", 1 }, 0);
            }
            else if (Item.Status == 1)
            {
                this.treeList1.AppendNode(new object[] { Item.RecruitmentCode.ToString(), Item.RecruitmentName.ToString(), "All", Item.FromDate.ToShortDateString(), Item.ToDate.ToShortDateString(), "Đang thực hiện tuyển dụng", 2 }, 0);
            }
            else
            {
                this.treeList1.AppendNode(new object[] { Item.RecruitmentCode.ToString(), Item.RecruitmentName.ToString(), "All", Item.FromDate.ToShortDateString(), Item.ToDate.ToShortDateString(), "Đ\x00e3 ho\x00e0n th\x00e0nh tuyển dụng", 3 }, 0);
            }
        }

        private void frm_Updated(object sender, HRM_RECRUITMENT Item)
        {
            TreeListHitInfo info = this.treeList1.CalcHitInfo(this.m_Point);
            this.treeList1.DeleteNode(info.Node);
            if (Item.Status == 0)
            {
                this.treeList1.AppendNode(new object[] { Item.RecruitmentCode.ToString(), Item.RecruitmentName.ToString(), "All", Item.FromDate.ToShortDateString(), Item.ToDate.ToShortDateString(), "Đang l\x00ean kế hoạch", 1 }, 0);
            }
            else if (Item.Status == 1)
            {
                this.treeList1.AppendNode(new object[] { Item.RecruitmentCode.ToString(), Item.RecruitmentName.ToString(), "All", Item.FromDate.ToShortDateString(), Item.ToDate.ToShortDateString(), "Đang thực hiện tuyển dụng", 2 }, 0);
            }
            else
            {
                this.treeList1.AppendNode(new object[] { Item.RecruitmentCode.ToString(), Item.RecruitmentName.ToString(), "All", Item.FromDate.ToShortDateString(), Item.ToDate.ToShortDateString(), "Đ\x00e3 ho\x00e0n th\x00e0nh tuyển dụng", 3 }, 0);
            }
        }

        private void InitializeComponent()
        {
            this.components = new Container();
            ComponentResourceManager manager = new ComponentResourceManager(typeof(xucRecruitment1));
            this.treeList1 = new TreeList();
            this.colRecruitmentName = new TreeListColumn();
            this.imgTree = new DevExpress.Utils.ImageCollection(this.components);
            this.toolTip1 = new ToolTipController(this.components);
            this.popupRecruitment = new PopupMenu(this.components);
            this.barSubItem1 = new BarSubItem();
            this.barButtonItem2 = new BarButtonItem();
            this.barButtonItem3 = new BarButtonItem();
            this.barButtonItem4 = new BarButtonItem();
            this.barButtonItem5 = new BarButtonItem();
            this.bbiAddRecruitment = new BarButtonItem();
            this.bbiEditRecruitment = new BarButtonItem();
            this.bbiDeleteRecruitment = new BarButtonItem();
            this.barButtonItem6 = new BarButtonItem();
            this.barButtonItem7 = new BarButtonItem();
            this.bbiProperties = new BarButtonItem();
            this.barManager1 = new BarManager(this.components);
            this.barDockControlTop = new BarDockControl();
            this.barDockControlBottom = new BarDockControl();
            this.barDockControlLeft = new BarDockControl();
            this.barDockControlRight = new BarDockControl();
            this.imageCollection2 = new DevExpress.Utils.ImageCollection(this.components);
            this.barButtonItem1 = new BarButtonItem();
            this.barMdiChildrenListItem1 = new BarMdiChildrenListItem();
            this.barToolbarsListItem1 = new BarToolbarsListItem();
            this.treeList1.BeginInit();
            this.imgTree.BeginInit();
            this.popupRecruitment.BeginInit();
            this.barManager1.BeginInit();
            this.imageCollection2.BeginInit();
            base.SuspendLayout();
            this.treeList1.Appearance.FocusedCell.BackColor = Color.Orange;
            this.treeList1.Appearance.FocusedCell.BackColor2 = Color.White;
            this.treeList1.Appearance.FocusedCell.GradientMode = LinearGradientMode.BackwardDiagonal;
            this.treeList1.Appearance.FocusedCell.Options.UseBackColor = true;
            this.treeList1.Columns.AddRange(new TreeListColumn[] { this.colRecruitmentName });
            this.treeList1.Dock = DockStyle.Fill;
            this.treeList1.DragNodesMode = TreeListDragNodesMode.Advanced;
            this.treeList1.KeyFieldName = "RecruitmentCode";
            this.treeList1.Location = new Point(0, 0);
            this.treeList1.Name = "treeList1";
            this.treeList1.OptionsBehavior.PopulateServiceColumns = true;
            this.treeList1.OptionsView.ShowHorzLines = false;
            this.treeList1.OptionsView.ShowVertLines = false;
            this.treeList1.ParentFieldName = "ManagerCode";
            this.treeList1.RootValue = "";
            this.treeList1.SelectImageList = this.imgTree;
            this.treeList1.Size = new Size(280, 0x236);
            this.treeList1.TabIndex = 1;
            this.treeList1.ToolTipController = this.toolTip1;
            this.treeList1.MouseDown += new MouseEventHandler(this.treeList1_MouseDown);
            this.treeList1.FocusedNodeChanged += new FocusedNodeChangedEventHandler(this.treeList1_FocusedNodeChanged);
            this.treeList1.GetSelectImage += new GetSelectImageEventHandler(this.treeList1_GetSelectImage);
            this.colRecruitmentName.Caption = "Đợt Tuyển Dụng";
            this.colRecruitmentName.FieldName = "RecruitmentName";
            this.colRecruitmentName.MinWidth = 230;
            this.colRecruitmentName.Name = "colRecruitmentName";
            this.colRecruitmentName.OptionsColumn.AllowEdit = false;
            this.colRecruitmentName.OptionsColumn.ReadOnly = true;
            this.colRecruitmentName.Visible = true;
            this.colRecruitmentName.VisibleIndex = 0;
            this.colRecruitmentName.Width = 230;
            this.imgTree.ImageStream = (ImageCollectionStreamer) manager.GetObject("imgTree.ImageStream");
            this.imgTree.Images.SetKeyName(0, "tab-new-raised.png");
            this.imgTree.Images.SetKeyName(1, "marker_rounded_grey_4.png");
            this.imgTree.Images.SetKeyName(2, "marker_rounded_orrange.png");
            this.imgTree.Images.SetKeyName(3, "marker_rounded_red.png");
            this.toolTip1.Rounded = true;
            this.toolTip1.ShowBeak = true;
            this.popupRecruitment.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.barSubItem1, true), new LinkPersistInfo(this.bbiAddRecruitment), new LinkPersistInfo(this.bbiEditRecruitment), new LinkPersistInfo(this.bbiDeleteRecruitment), new LinkPersistInfo(this.barButtonItem6, true), new LinkPersistInfo(this.barButtonItem7), new LinkPersistInfo(this.bbiProperties, true) });
            this.popupRecruitment.Manager = this.barManager1;
            this.popupRecruitment.Name = "popupRecruitment";
            this.barSubItem1.Caption = "Hiển thị";
            this.barSubItem1.Id = 7;
            this.barSubItem1.LinksPersistInfo.AddRange(new LinkPersistInfo[] { new LinkPersistInfo(this.barButtonItem2), new LinkPersistInfo(this.barButtonItem3, true), new LinkPersistInfo(this.barButtonItem4), new LinkPersistInfo(this.barButtonItem5) });
            this.barSubItem1.Name = "barSubItem1";
            this.barSubItem1.Visibility = BarItemVisibility.Never;
            this.barButtonItem2.Caption = "Tất cả ứng vi\x00ean trong đợt tuyển dụng n\x00e0y";
            this.barButtonItem2.Id = 8;
            this.barButtonItem2.ImageIndex = 0x27;
            this.barButtonItem2.Name = "barButtonItem2";
            this.barButtonItem3.Caption = "Chỉ những ứng vi\x00ean đ\x00e3 tr\x00fang tuyển";
            this.barButtonItem3.Id = 9;
            this.barButtonItem3.Name = "barButtonItem3";
            this.barButtonItem4.Caption = "Chỉ những ứng vi\x00ean chưa tr\x00fang tuyển";
            this.barButtonItem4.Id = 10;
            this.barButtonItem4.Name = "barButtonItem4";
            this.barButtonItem5.Caption = "Tất cả ứng vi\x00ean đang l\x00e0m việc tại c\x00f4ng ty";
            this.barButtonItem5.Id = 11;
            this.barButtonItem5.Name = "barButtonItem5";
            this.bbiAddRecruitment.Caption = "Th\x00eam đợt tuyển dụng";
            this.bbiAddRecruitment.Id = 0;
            this.bbiAddRecruitment.ImageIndex = 0x45;
            this.bbiAddRecruitment.Name = "bbiAddRecruitment";
            this.bbiAddRecruitment.Visibility = BarItemVisibility.Never;
            this.bbiEditRecruitment.Caption = "Sửa đợt n\x00e0y";
            this.bbiEditRecruitment.Id = 1;
            this.bbiEditRecruitment.ImageIndex = 14;
            this.bbiEditRecruitment.Name = "bbiEditRecruitment";
            this.bbiEditRecruitment.ItemClick += new ItemClickEventHandler(this.bbiEditRecruitment_ItemClick);
            this.bbiDeleteRecruitment.Caption = "X\x00f3a đợt n\x00e0y";
            this.bbiDeleteRecruitment.Id = 2;
            this.bbiDeleteRecruitment.ImageIndex = 13;
            this.bbiDeleteRecruitment.Name = "bbiDeleteRecruitment";
            this.bbiDeleteRecruitment.ItemClick += new ItemClickEventHandler(this.bbiDeleteRecruitment_ItemClick);
            this.barButtonItem6.Caption = "Th\x00eam v\x00e0o ứng vi\x00ean";
            this.barButtonItem6.Id = 12;
            this.barButtonItem6.Name = "barButtonItem6";
            this.barButtonItem6.Visibility = BarItemVisibility.Never;
            this.barButtonItem7.Caption = "X\x00f3a tất cả ứng vi\x00ean";
            this.barButtonItem7.Id = 13;
            this.barButtonItem7.ImageIndex = 0x16;
            this.barButtonItem7.Name = "barButtonItem7";
            this.barButtonItem7.Visibility = BarItemVisibility.Never;
            this.bbiProperties.Caption = "Bảng thuộc t\x00ednh";
            this.bbiProperties.Id = 3;
            this.bbiProperties.ImageIndex = 8;
            this.bbiProperties.Name = "bbiProperties";
            this.bbiProperties.Visibility = BarItemVisibility.Never;
            this.barManager1.DockControls.Add(this.barDockControlTop);
            this.barManager1.DockControls.Add(this.barDockControlBottom);
            this.barManager1.DockControls.Add(this.barDockControlLeft);
            this.barManager1.DockControls.Add(this.barDockControlRight);
            this.barManager1.Form = this;
            this.barManager1.Images = this.imageCollection2;
            this.barManager1.Items.AddRange(new BarItem[] { this.bbiAddRecruitment, this.bbiEditRecruitment, this.bbiDeleteRecruitment, this.bbiProperties, this.barButtonItem1, this.barMdiChildrenListItem1, this.barToolbarsListItem1, this.barSubItem1, this.barButtonItem2, this.barButtonItem3, this.barButtonItem4, this.barButtonItem5, this.barButtonItem6, this.barButtonItem7 });
            this.barManager1.MaxItemId = 14;
            this.imageCollection2.ImageStream = (ImageCollectionStreamer) manager.GetObject("imageCollection2.ImageStream");
            this.imageCollection2.Images.SetKeyName(0x3d, "Vista (35).ico");
            this.imageCollection2.Images.SetKeyName(0x3e, "Security.ico");
            this.imageCollection2.Images.SetKeyName(0x3f, "RibbonPrintPreview_DocumentMapLarge.png");
            this.imageCollection2.Images.SetKeyName(0x40, "11.png");
            this.imageCollection2.Images.SetKeyName(0x41, "Sua.png");
            this.imageCollection2.Images.SetKeyName(0x42, "Them.png");
            this.imageCollection2.Images.SetKeyName(0x43, "PhanQuyen.png");
            this.imageCollection2.Images.SetKeyName(0x44, "11.png");
            this.imageCollection2.Images.SetKeyName(0x45, "plus.png");
            this.barButtonItem1.Caption = "Hiển thị";
            this.barButtonItem1.Id = 4;
            this.barButtonItem1.Name = "barButtonItem1";
            this.barMdiChildrenListItem1.Caption = "barMdiChildrenListItem1";
            this.barMdiChildrenListItem1.Id = 5;
            this.barMdiChildrenListItem1.Name = "barMdiChildrenListItem1";
            this.barToolbarsListItem1.Caption = "barToolbarsListItem1";
            this.barToolbarsListItem1.Id = 6;
            this.barToolbarsListItem1.Name = "barToolbarsListItem1";
            base.AutoScaleDimensions = new SizeF(6f, 13f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.treeList1);
            base.Controls.Add(this.barDockControlLeft);
            base.Controls.Add(this.barDockControlRight);
            base.Controls.Add(this.barDockControlBottom);
            base.Controls.Add(this.barDockControlTop);
            base.Name = "xucRecruitment1";
            base.Size = new Size(280, 0x236);
            this.treeList1.EndInit();
            this.imgTree.EndInit();
            this.popupRecruitment.EndInit();
            this.barManager1.EndInit();
            this.imageCollection2.EndInit();
            base.ResumeLayout(false);
        }

        private void InitMultiLanguages()
        {
            this.bbiEditRecruitment.Caption = MultiLanguages.GetString("tbl_Recruitment", "EditRecruitment", "Sửa đợt n\x00e0y");
            this.bbiDeleteRecruitment.Caption = MultiLanguages.GetString("tbl_Recruitment", "DeleteRecruitment", "X\x00f3a đợt n\x00e0y");
            this.colRecruitmentName.Caption = MultiLanguages.GetString("tbl_Recruitment", "Recruitment", "Đợt tuyển dụng");
        }

        public void LoadControl()
        {
            this.LoadTreeList();
        }

        private void LoadTreeList()
        {
            DataTable list = new HRM_RECRUITMENT().GetList();
            this.dt1 = new DataTable();
            this.dt1.Columns.Add("RecruitmentCode");
            this.dt1.Columns.Add("RecruitmentName");
            this.dt1.Columns.Add("ManagerCode");
            this.dt1.Columns.Add("FromDate");
            this.dt1.Columns.Add("ToDate");
            this.dt1.Columns.Add("Status");
            this.dt1.Columns.Add("ImageIndex");
            this.dt1.Rows.Add(new object[] { "", MultiLanguages.GetString("tbl_Recruitment", "All", "Tất Cả"), "", System.DateTime.Now, System.DateTime.Now, "Not", 0 });
            foreach (DataRow row in list.Rows)
            {
                if (row["Status"].ToString() == "0")
                {
                    this.dt1.Rows.Add(new object[] { row["RecruitmentCode"].ToString(), row["RecruitmentName"].ToString(), "", System.DateTime.Parse(row["FromDate"].ToString()).ToShortDateString(), System.DateTime.Parse(row["ToDate"].ToString()).ToShortDateString(), "Đang l\x00ean kế hoạch", 1 });
                }
                else if (row["Status"].ToString() == "1")
                {
                    this.dt1.Rows.Add(new object[] { row["RecruitmentCode"].ToString(), row["RecruitmentName"].ToString(), "", System.DateTime.Parse(row["FromDate"].ToString()).ToShortDateString(), System.DateTime.Parse(row["ToDate"].ToString()).ToShortDateString(), "Đang thực hiện tuyển dụng", 2 });
                }
                else
                {
                    this.dt1.Rows.Add(new object[] { row["RecruitmentCode"].ToString(), row["RecruitmentName"].ToString(), "", System.DateTime.Parse(row["FromDate"].ToString()).ToShortDateString(), System.DateTime.Parse(row["ToDate"].ToString()).ToShortDateString(), "Đ\x00e3 ho\x00e0n th\x00e0nh tuyển dụng", 3 });
                }
            }
            this.treeList1.DataSource = this.dt1;
            this.treeList1.ExpandAll();
        }

        public void RaiseSelectedEventHander(string Value)
        {
            if (this.Selected != null)
            {
                this.Selected(this, Value);
            }
        }

        private void RecruitmentChange(TreeListHitInfo hi)
        {
            DataRowView dataRecordByNode = (DataRowView) this.treeList1.GetDataRecordByNode(hi.Node);
            HRM_RECRUITMENT item = new HRM_RECRUITMENT();
            if (item.Get(dataRecordByNode["RecruitmentCode"].ToString()) != "OK")
            {
                XtraMessageBox.Show("Dữ liệu kh\x00f4ng tồn tại", "Th\x00f4ng B\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                xfmRecruitmentAdd add = new xfmRecruitmentAdd(Actions.Update, item);
                add.Updated += new xfmRecruitmentAdd.UpdatedEventHander(this.frm_Updated);
                add.Added += new xfmRecruitmentAdd.AddedEventHander(this.frm_Added);
                add.ShowDialog();
            }
        }

        private void RecruitmentDelete(TreeListHitInfo hi)
        {
            DataRowView dataRecordByNode = (DataRowView) this.treeList1.GetDataRecordByNode(hi.Node);
            if (!ClsOption.System2.IsQuestion || (XtraMessageBox.Show("Bạn c\x00f3 muốn x\x00f3a kh\x00f4ng?", "Th\x00f4ng b\x00e1o", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.No))
            {
                string str = "";
                HRM_RECRUITMENT hrm_recruitment = new HRM_RECRUITMENT();
                string reference = dataRecordByNode["RecruitmentCode"].ToString();
                SYS_LOG.Insert("Đợt Tuyển Dụng", "Xo\x00e1", reference);
                str = hrm_recruitment.Delete(reference);
                if (str == "OK")
                {
                    this.treeList1.DeleteNode(hi.Node);
                }
                else if (str != "OK")
                {
                    MessageBox.Show("Th\x00f4ng tin kh\x00f4ng được x\x00f3a\n" + str, "Th\x00f4ng b\x00e1o", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                }
            }
        }

        private void ShowMenu(TreeListHitInfo hi, Point point)
        {
            if (hi.Node != null)
            {
                if (hi.Node.Level == 0)
                {
                    this.bbiEditRecruitment.Enabled = false;
                    this.bbiDeleteRecruitment.Enabled = false;
                    this.bbiProperties.Enabled = false;
                }
                else
                {
                    this.bbiEditRecruitment.Enabled = true;
                    this.bbiDeleteRecruitment.Enabled = true;
                    this.bbiProperties.Enabled = true;
                }
                this.popupRecruitment.ShowPopup(point);
            }
            this.treeList1.SetFocusedNode(hi.Node);
        }

        private void ShowToolTip(TreeListHitInfo hi)
        {
            try
            {
                DataRowView dataRecordByNode = (DataRowView) this.treeList1.GetDataRecordByNode(hi.Node);
                if (hi.Node.Level == 1)
                {
                    this.toolTip1.ShowHint("Từ ng\x00e0y: " + dataRecordByNode["FromDate"].ToString() + Environment.NewLine + "Đến ng\x00e0y: " + dataRecordByNode["ToDate"].ToString() + Environment.NewLine + "Trạng th\x00e1i: " + dataRecordByNode["Status"].ToString(), dataRecordByNode["RecruitmentName"].ToString());
                }
            }
            catch
            {
            }
        }

        private void treeList1_FocusedNodeChanged(object sender, FocusedNodeChangedEventArgs e)
        {
            try
            {
                DataRowView dataRecordByNode = (DataRowView) this.treeList1.GetDataRecordByNode(e.Node);
                this.RaiseSelectedEventHander(dataRecordByNode["RecruitmentCode"].ToString());
            }
            catch
            {
            }
        }

        private void treeList1_GetSelectImage(object sender, GetSelectImageEventArgs e)
        {
            DataRowView dataRecordByNode = (DataRowView) this.treeList1.GetDataRecordByNode(e.Node);
            e.NodeImageIndex = int.Parse(dataRecordByNode["ImageIndex"].ToString());
        }

        private void treeList1_MouseDown(object sender, MouseEventArgs e)
        {
            this.m_Point = new Point(e.X, e.Y);
            if (e.Button == MouseButtons.Right)
            {
                this.ShowMenu(this.treeList1.CalcHitInfo(this.m_Point), this.treeList1.PointToScreen(this.m_Point));
            }
            if (e.Button == MouseButtons.Left)
            {
                this.ShowToolTip(this.treeList1.CalcHitInfo(this.m_Point));
            }
        }

        public delegate void SelectedEventHander(object sender, string Value);
    }
}

